package com.gateway.config;

import org.springframework.cloud.gateway.route.RouteLocator;
import org.springframework.cloud.gateway.route.builder.RouteLocatorBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 网关配置类
 * 用于编程式定义路由
 */
@Configuration
public class GatewayConfig {

    /**
     * 配置路由
     * 注意：这里的路由配置会与application.yml中的配置合并
     */
    @Bean
    public RouteLocator customRouteLocator(RouteLocatorBuilder builder) {
        return builder.routes()
                // 定义API文档路由
                .route("api_docs_route", r -> r.path("/v3/api-docs/**")
                        .uri("lb://activity-service"))
                
                // 定义Swagger UI路由
                .route("swagger_ui_route", r -> r.path("/swagger-ui/**")
                        .uri("lb://activity-service"))
                
                // 定义降级路由
                .route("fallback_route", r -> r.path("/fallback/**")
                        .uri("http://localhost:8090"))
                
                .build();
    }
} 